package com.ruoyi.project.module.yzx.jishi.controller;

import java.time.Duration;
import java.time.Instant;
import java.util.*;

import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.*;
import com.ruoyi.project.service.*;
import com.ruoyi.project.service.impl.YqgTechnicianRehearsalServiceImpl;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

import javax.annotation.Resource;

import static com.ruoyi.common.security.utils.SecurityUtils.getLoginUser;
import static com.ruoyi.common.security.utils.SecurityUtils.getUserId;

/**
 * 消费详细Controller
 *
 * @author dr
 * @date 2023-04-17
 */
@RestController
@RequestMapping("/yzx/jishi/details")
public class YzxConsumptionDetailsController extends BaseController {
    @Autowired
    private IYqgConsumptionDetailsService yqgConsumptionDetailsService;
    @Autowired
    private IYqgInformationProjectService yqgInformationProjectService;
    @Autowired
    private IYqgBaseinfoService yqgBaseinfoService;
    @Autowired
    private IYqgInformationRoomService yqgInformationRoomService;
    @Autowired
    private IYqgHandsService yqgHandsService;
    @Resource
    private IYqgBarBillsService yqgBarBillsService;

    @Autowired
    private IYqgTechnicianClockTableService yqgTechnicianClockTableService;

    @Autowired
    private IYqgTechnicianRehearsalService yqgTechnicianRehearsalService;


    @GetMapping("/listsz")
    //查询技师状态
    public AjaxResult listsz() {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //设置整体查询条件1
        YqgBaseinfo yqgBaseinfo = new YqgBaseinfo();
        yqgBaseinfo.setUserName(sysUser.getUserName());
        //分页
        List<YqgBaseinfo> list = yqgBaseinfoService.selectYqgBaseinfoList(yqgBaseinfo);
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getPersonnelStatus().equals("1")) {
                return AjaxResult.success("已上钟", 1);
            }
        }
        return AjaxResult.success("未上钟", 2);
    }

    @GetMapping("/listtd")
    //退单查询
    public TableDataInfo listtd(YqgConsumptionDetails yqgConsumptionDetails) {
        //设置吧台查询条件
        YqgBarBills yqgBarBills = new YqgBarBills();
        YqgBarBills yqgBarBills1 = new YqgBarBills();
        //设置消费查询条件
        YqgConsumptionDetails yqgConsumptionDetails1 = new YqgConsumptionDetails();
        //从吧台表中查出对应id的项
        yqgBarBills.setID(yqgConsumptionDetails.getBarBillsId());
        yqgBarBills.setHandState("1");
        List<YqgBarBills> list = yqgBarBillsService.selectYqgBarBillsList(yqgBarBills);
        for (int i = 0; i < list.size(); i++) {
            yqgBarBills1 = list.get(i);
        }
        yqgConsumptionDetails1.setBarBillsId(yqgBarBills1.getID());
        yqgConsumptionDetails1.setProjectCategory(yqgConsumptionDetails.getProjectCategory());
        yqgConsumptionDetails1.setConsumptionStatus("0");
        List<YqgConsumptionDetails> listr = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails1);
        return getDataTable(listr);

    }
    @GetMapping("/listtd1")
    //退单查询
    public TableDataInfo listtd1(YqgConsumptionDetails yqgConsumptionDetails) {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //分页
        startPage();
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        return getDataTable(list);
    }

    @GetMapping("/list")
    //基础查询（当前用户）
    public TableDataInfo list(YqgConsumptionDetails yqgConsumptionDetails) {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //设置整体查询条件1
      yqgConsumptionDetails.setUserId(sysUser.getUserId());
        //分页
        startPage();
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        return getDataTable(list);
    }

    @GetMapping("/list1")
    //费用查询查询两日内已经下钟情况
    public TableDataInfo list0(YqgConsumptionDetails yqgConsumptionDetails) {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //只查询当前用户
        yqgConsumptionDetails.setUserId(sysUser.getUserId());
        //查询1，查出今天的信息
        yqgConsumptionDetails.setNextClockTime(new Date());
        //存在list中
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.YzxselectYqgConsumptionDetailsList(yqgConsumptionDetails);
        //使用时间操作类
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -1);
        //得到昨天的结果
        Date DT = calendar.getTime();
        //查询上一天的项目
        YqgConsumptionDetails yqgConsumptionDetails2 = new YqgConsumptionDetails();
        yqgConsumptionDetails2.setNextClockStatus("0");
        yqgConsumptionDetails2.setNextClockTime(DT);
        //存在lista中
        List<YqgConsumptionDetails> listA = yqgConsumptionDetailsService.YzxselectYqgConsumptionDetailsList(yqgConsumptionDetails2);
        //拼在一起，得到最终结果
        List<YqgConsumptionDetails> listB = new ArrayList<>(list);
        listB.addAll(listA);
        //返回
        return getDataTable(listB);
    }

    @GetMapping("/listpj")
    //换钟页面查询
    public TableDataInfo list1() {
        //新建消费表对象用于查询
        YqgConsumptionDetails yqgConsumptionDetails = new YqgConsumptionDetails();
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //设置消费表查询条件
        yqgConsumptionDetails.setUserId(sysUser.getUserId());
        yqgConsumptionDetails.setNextClockStatus("1");
        //查询消费表
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        return getDataTable(list);
    }

    @GetMapping("/list2")
    //查询还有多长时间下钟
    //仅限单次上钟的
    public TableDataInfo list2(YqgConsumptionDetails yqgConsumptionDetails) {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //设置整体查询条件1
        yqgConsumptionDetails.setUserId(sysUser.getUserId());
        //创建项目表对象用作查询
        YqgInformationProject cxP = new YqgInformationProject();
        //新建项目表对象用于接受查询结果
        YqgInformationProject jlP = new YqgInformationProject();
        //创建消费表对象用作查询
        YqgConsumptionDetails cxD = new YqgConsumptionDetails();
        //新建消费表对象用于接受查询结果
        YqgConsumptionDetails jlD = new YqgConsumptionDetails();
        //查询一条查询条件
        cxD.setUserId(sysUser.getUserId());
        cxD.setNextClockStatus("1");
        //查询整体消费表
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(cxD);
        for (int i = 0; i < list.size(); i++) {
            jlD = list.get(i);
        }
        if (jlD.getID() == null) {
            return null;
        }
        //设置项目表查询条件
        cxP.setProjectCode(jlD.getProjectCode());
        //查询项目表
        List<YqgInformationProject> list2 = yqgInformationProjectService.selectYqgInformationProjectList(cxP);
        for (int j = 0; j < list2.size(); j++) {
            jlP = list2.get(j);
        }
        //获取消费表中上钟时间
        Date CT = jlD.getClockTime();
        //新建calenda对象
        Calendar calendar = Calendar.getInstance();
        //设置时间类型
        calendar.setTime(CT);
        //获取项目表中项目持续时间
        String cut = jlP.getClockUpTime();
        //将其转化成小时和分钟
        int icut = Integer.parseInt(cut);
        int addHours = icut / 60;
        int addMinutes = icut % 60;
        //把他们分别加到上钟时间上
        calendar.add(Calendar.HOUR, addHours);
        calendar.add(Calendar.MINUTE, addMinutes);
        //获得应下钟时间
        Date DT = calendar.getTime();
        //获取当前时间
        Date N = DateUtils.getNowDate();
        //比较时间差
        Instant instant1 = N.toInstant();
        Instant instant2 = DT.toInstant();
        Duration duration = Duration.between(instant1, instant2);
        //获取时间差
        long minutes = duration.toMinutes();
        //给前台传时分秒需要转成String
        jlD.setNote1(String.valueOf(minutes));
        yqgConsumptionDetailsService.updateYqgConsumptionDetails(jlD);
        startPage();
        List<YqgConsumptionDetails> result = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails);
        return getDataTable(result);
    }

    @Log(title = "消费详细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    //加钟
    public AjaxResult add(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();

        //查询并修改room表
        YqgInformationRoom yqgInformationRoom = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom1 = new YqgInformationRoom();
        yqgInformationRoom.setRoomNumber(yqgConsumptionDetails.getSeat());
        //取出对应房间的那一条数据
        List<YqgInformationRoom> list3 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom);
        for (int i = 0; i < list3.size(); i++) {
            yqgInformationRoom1 = list3.get(i);
        }
        //判断是否是大厅。如果是大厅则直接赋予状态


        //将项目，技师录入room表
        yqgInformationRoom1.setEntryName(yqgConsumptionDetails.getEntryName());
        yqgInformationRoom1.setArtificer(String.valueOf(sysUser.getUserId()));
        yqgInformationRoom1.setActualTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
        yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom1);
        //新建吧台对象
        YqgBarBills yqgBarBills = new YqgBarBills();
        //设置吧台查询条件
        yqgBarBills.setHandBrand(yqgConsumptionDetails.getHandBrand());
        yqgBarBills.setHandState("1");
        List<YqgBarBills> batailist = yqgBarBillsService.selectYqgBarBillsList(yqgBarBills);
        if (batailist.size() != 1) {
            //如果状态不为1则是未开牌或者有问题
            return AjaxResult.error("未开牌");
        } else {
            //将前台传来的参数加上后台赋予的参数作为修改条件
            yqgConsumptionDetails.setUserId(sysUser.getUserId());
            yqgConsumptionDetails.setClockTime(DateUtils.getNowDate());
            yqgConsumptionDetails.setNextClockStatus("1");
            //将技师状态修改为上钟
            YqgBaseinfo yqgBaseinfo = new YqgBaseinfo();
            YqgBaseinfo yB = new YqgBaseinfo();
            yqgBaseinfo.setUserName(sysUser.getUserName());
            List<YqgBaseinfo> list = yqgBaseinfoService.selectYqgBaseinfoList(yqgBaseinfo);
            for (int i = 0; i < list.size(); i++) {
                yB = list.get(i);
            }
            yB.setPersonnelStatus("1");
            yqgBaseinfoService.updateYqgBaseinfo(yB);
            //新建项目表对象做查询
            YqgInformationProject yqgInformationProject = new YqgInformationProject();
            //查询项目信息
            yqgInformationProject.setEntryName(yqgConsumptionDetails.getEntryName());
            List<YqgInformationProject> a = yqgInformationProjectService.selectYqgInformationProjectList(yqgInformationProject);
            //以下为吧台需要 字段数据
            /**
             * 添加用户信息
             */
            //添加用户id
            yqgConsumptionDetails.setUserId(sysUser.getUserId());
            //添加用户姓名
            yqgConsumptionDetails.setUserName(sysUser.getUserName());
            //添加用户部门
            yqgConsumptionDetails.setDeptId(sysUser.getDeptId());
            yqgConsumptionDetails.setDepartment("4");
            //添加昵称
            yqgConsumptionDetails.setNickName(sysUser.getNickName());
            //添加手牌状态
            yqgConsumptionDetails.setHandState("1");
            /**
             * 添加项目信息
             */
            //添加项目名称
            yqgConsumptionDetails.setEntryName(a.get(0).getEntryName());
            //添加项目类别
            yqgConsumptionDetails.setProjectCategory(a.get(0).getProjectCategory());
            //添加项目代码
            yqgConsumptionDetails.setMnemonicCode(a.get(0).getMnemonicCode());
            //添加代码
            yqgConsumptionDetails.setProjectCode(a.get(0).getProjectCode());
            //添加单位
            yqgConsumptionDetails.setUnit(a.get(0).getUnit());
            //添加单价
            yqgConsumptionDetails.setUnitPrice(a.get(0).getUnitPrice());
            //添加提成
            yqgConsumptionDetails.setCommissionPrice(a.get(0).getCommissionPrice());
            /**
             * 账单信息
             */
            //添加账单id
            yqgConsumptionDetails.setBarBillsId(batailist.get(0).getID());
            //添加留牌状态
            yqgConsumptionDetails.setRetentionStatus(batailist.get(0).getRetentionStatus());
            //添加并牌状态
            yqgConsumptionDetails.setMergeStatus(batailist.get(0).getMergeStatus());
            //添加同来
            yqgConsumptionDetails.setTogether(batailist.get(0).getTogether());
            //添加到店时间
            yqgConsumptionDetails.setOpeningTime(DateUtils.getNowDate());
            //添加手牌类别
            yqgConsumptionDetails.setHandCategory(batailist.get(0).getHandCategory());
            //原手牌
            yqgConsumptionDetails.setOriginalHand(batailist.get(0).getOriginalHand());
            //交班状态
            yqgConsumptionDetails.setHandoverStatus(batailist.get(0).getHandoverStatus());
            /**
             * 消费信息
             */
            //添加录单时间
            yqgConsumptionDetails.setRecordingTime(yqgConsumptionDetails.getClockTime());
            //添加数量
            if (yqgConsumptionDetails.getQuantity() == null) {
                yqgConsumptionDetails.setQuantity("1");
            }
            //添加消费状态
            yqgConsumptionDetails.setConsumptionStatus("0");
            //将上钟时间时分秒存入note2
            yqgConsumptionDetails.setNote2(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
            yqgConsumptionDetailsService.insertYqgConsumptionDetails(yqgConsumptionDetails);
            //在加钟时将数据传入技师上钟情况表
            int q = Integer.parseInt(yqgConsumptionDetails.getQuantity());
            for (int i = 0; i < q; i++) {
                YqgTechnicianClockTable yqgTechnicianClockTable = new YqgTechnicianClockTable();
                yqgTechnicianClockTable.setRegistrationTime(DateUtils.getNowDate());
                yqgTechnicianClockTable.setUpclockPosition(yqgConsumptionDetails.getSeat());
                yqgTechnicianClockTable.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
                yqgTechnicianClockTable.setClockTime(yqgConsumptionDetails.getClockTime());
                yqgTechnicianClockTable.setEntryName(yqgConsumptionDetails.getEntryName());
                yqgTechnicianClockTable.setTableCreationTime(new Date());
                yqgTechnicianClockTable.setHandBrand(yqgConsumptionDetails.getHandBrand());
                yqgTechnicianClockTable.setNote1("1");
                yqgTechnicianClockTableService.insertYqgTechnicianClockTable(yqgTechnicianClockTable);
            }
            return AjaxResult.success("上钟成功");
        }
    }


    @Log(title = "消费详细", businessType = BusinessType.INSERT)
    @PostMapping("/add1")
    //排队上钟
    public AjaxResult add1(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {


        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();

        YqgTechnicianRehearsal yqgTechnicianRehearsal = new YqgTechnicianRehearsal();
        yqgTechnicianRehearsal.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
        List<YqgTechnicianRehearsal> listtj = yqgTechnicianRehearsalService.selectYqgTechnicianRehearsalList(yqgTechnicianRehearsal);
        Long[] L = new Long[1000];
        String ph = null;
        for (int i = 0; i < listtj.size(); i++) {
            L[i] = listtj.get(i).getId();
            ph = listtj.get(i).getRowNumber();
            System.out.println(ph);
        }
        System.out.println(L);

        yqgTechnicianRehearsalService.deleteYqgTechnicianRehearsalByIds(L);
        //查询并修改room表
        YqgInformationRoom yqgInformationRoom = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom1 = new YqgInformationRoom();
        //新建吧台对象
        YqgBarBills yqgBarBills = new YqgBarBills();
        //设置吧台查询条件
        yqgBarBills.setHandBrand(yqgConsumptionDetails.getHandBrand());
        yqgBarBills.setHandState("1");
        List<YqgBarBills> batailist = yqgBarBillsService.selectYqgBarBillsList(yqgBarBills);
        if (batailist.size() != 1) {
            //如果状态不为1则是未开牌或者有问题
            return AjaxResult.error("未开牌");
        } else {
            //将前台传来的参数加上后台赋予的参数作为修改条件
            yqgConsumptionDetails.setUserId(sysUser.getUserId());
            yqgConsumptionDetails.setClockTime(DateUtils.getNowDate());
            yqgConsumptionDetails.setNextClockStatus("1");
            //将技师状态修改为上钟

            //将消费表中位置作为房间号修改房间状态
            yqgInformationRoom.setRoomNumber(yqgConsumptionDetails.getSeat());
            //取出对应房间的那一条数据
            List<YqgInformationRoom> list3 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom);
            if(list3.size()==0)
            {
                return AjaxResult.error("不存在该房间");
            }else {
                for (int i = 0; i < list3.size(); i++) {
                    yqgInformationRoom1 = list3.get(i);
                }
                //判断是否是大厅。如果是大厅则直接赋予状态

                if (yqgInformationRoom1.getRoomStatus().equals("1")) {
                    return AjaxResult.error("该位置已占用");
                } else {
                    yqgInformationRoom1.setRoomStatus("1");
                }

                //将项目，技师录入room表
                yqgInformationRoom1.setEntryName(yqgConsumptionDetails.getEntryName());
                yqgInformationRoom1.setArtificer(String.valueOf(sysUser.getUserId()));
                yqgInformationRoom1.setActualTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
                yqgInformationRoom1.setHandBrand(yqgConsumptionDetails.getHandBrand());
                yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom1);


                YqgBaseinfo yqgBaseinfo = new YqgBaseinfo();
                YqgBaseinfo yB = new YqgBaseinfo();
                yqgBaseinfo.setUserName(sysUser.getUserName());
                List<YqgBaseinfo> list = yqgBaseinfoService.selectYqgBaseinfoList(yqgBaseinfo);
                for (int i = 0; i < list.size(); i++) {
                    yB = list.get(i);
                }
                yB.setPersonnelStatus("1");
                yqgBaseinfoService.updateYqgBaseinfo(yB);
                //新建项目表对象做查询
                YqgInformationProject yqgInformationProject = new YqgInformationProject();
                //查询项目信息
                yqgInformationProject.setEntryName(yqgConsumptionDetails.getEntryName());
                List<YqgInformationProject> a = yqgInformationProjectService.selectYqgInformationProjectList(yqgInformationProject);
                //以下为吧台需要 字段数据
                /**
                 * 添加用户信息
                 */
                //添加用户id
                yqgConsumptionDetails.setUserId(sysUser.getUserId());
                //添加用户姓名
                yqgConsumptionDetails.setUserName(sysUser.getUserName());
                //添加用户部门
                yqgConsumptionDetails.setDeptId(sysUser.getDeptId());
                //添加昵称
                yqgConsumptionDetails.setNickName(sysUser.getNickName());
                //添加手牌状态
                yqgConsumptionDetails.setHandState("1");
                yqgConsumptionDetails.setDepartment("4");
                /**
                 * 添加项目信息
                 */
                //添加项目名称
                yqgConsumptionDetails.setEntryName(a.get(0).getEntryName());
                //添加项目类别
                yqgConsumptionDetails.setProjectCategory(a.get(0).getProjectCategory());
                //添加项目代码
                yqgConsumptionDetails.setMnemonicCode(a.get(0).getMnemonicCode());
                //添加代码
                yqgConsumptionDetails.setProjectCode(a.get(0).getProjectCode());
                //添加单位
                yqgConsumptionDetails.setUnit(a.get(0).getUnit());
                //添加单价
                yqgConsumptionDetails.setUnitPrice(a.get(0).getUnitPrice());
                //添加提成
                yqgConsumptionDetails.setCommissionPrice(a.get(0).getCommissionPrice());
                yqgConsumptionDetails.setQuantity("1");
                yqgConsumptionDetails.setTotalAmount(a.get(0).getUnitPrice());
                /**
                 * 账单信息
                 */
                //添加账单id
                yqgConsumptionDetails.setBarBillsId(batailist.get(0).getID());
                //添加留牌状态
                yqgConsumptionDetails.setRetentionStatus(batailist.get(0).getRetentionStatus());
                //添加并牌状态
                yqgConsumptionDetails.setMergeStatus(batailist.get(0).getMergeStatus());
                //添加同来
                yqgConsumptionDetails.setTogether(batailist.get(0).getTogether());
                //添加到店时间
                yqgConsumptionDetails.setOpeningTime(DateUtils.getNowDate());
                //添加手牌类别
                yqgConsumptionDetails.setHandCategory(batailist.get(0).getHandCategory());
                //原手牌
                yqgConsumptionDetails.setOriginalHand(batailist.get(0).getOriginalHand());
                //交班状态
                yqgConsumptionDetails.setHandoverStatus(batailist.get(0).getHandoverStatus());
                /**
                 * 消费信息
                 */
                //添加录单时间
                yqgConsumptionDetails.setRecordingTime(yqgConsumptionDetails.getClockTime());
                //添加数量
                if (yqgConsumptionDetails.getQuantity() == null) {
                    yqgConsumptionDetails.setQuantity("1");
                }
                //添加消费状态
                yqgConsumptionDetails.setConsumptionStatus("0");
                //将上钟时间时分秒存入note2
                yqgConsumptionDetails.setNote2(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
                yqgConsumptionDetailsService.insertYqgConsumptionDetails(yqgConsumptionDetails);
                //排队上钟时将数据传入技师上钟情况表
                //YqgTechnicianRehearsal yqgTechnicianRehearsal=new YqgTechnicianRehearsal();
                YqgTechnicianClockTable yqgTechnicianClockTable = new YqgTechnicianClockTable();
                yqgTechnicianClockTable.setRegistrationTime(DateUtils.getNowDate());
                yqgTechnicianClockTable.setRowNumber(ph);
                yqgTechnicianClockTable.setUpclockPosition(yqgConsumptionDetails.getSeat());
                yqgTechnicianClockTable.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
                yqgTechnicianClockTable.setClockTime(yqgConsumptionDetails.getClockTime());
                yqgTechnicianClockTable.setEntryName(yqgConsumptionDetails.getEntryName());
                yqgTechnicianClockTable.setTableCreationTime(new Date());
                yqgTechnicianClockTable.setHandBrand(yqgConsumptionDetails.getHandBrand());
                yqgTechnicianClockTable.setNote1("1");
                yqgTechnicianClockTableService.insertYqgTechnicianClockTable(yqgTechnicianClockTable);

                return AjaxResult.success("上钟成功");
            }
        }
    }

    @Log(title = "消费详细", businessType = BusinessType.INSERT)
    @PostMapping("/add2")
    //叫去上钟
    public AjaxResult add2(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //查询并修改room表
        YqgInformationRoom yqgInformationRoom = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom1 = new YqgInformationRoom();
        //新建吧台对象
        YqgBarBills yqgBarBills = new YqgBarBills();
        //设置吧台查询条件
        yqgBarBills.setHandBrand(yqgConsumptionDetails.getHandBrand());
        yqgBarBills.setHandState("1");
        List<YqgBarBills> batailist = yqgBarBillsService.selectYqgBarBillsList(yqgBarBills);
        if (batailist.size() != 1) {
            //如果状态不为1则是未开牌或者有问题
            return AjaxResult.error("未开牌");
        } else {
            //将前台传来的参数加上后台赋予的参数作为修改条件
            yqgConsumptionDetails.setUserId(sysUser.getUserId());
            yqgConsumptionDetails.setClockTime(DateUtils.getNowDate());
            yqgConsumptionDetails.setNextClockStatus("1");

            //将消费表中位置作为房间号修改房间状态
            yqgInformationRoom.setRoomNumber(yqgConsumptionDetails.getSeat());
            //取出对应房间的那一条数据
            List<YqgInformationRoom> list3 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom);
            if(list3.size()==0)
            {
                return AjaxResult.error("不存在该房间");
            }else {
                for (int i = 0; i < list3.size(); i++) {
                    yqgInformationRoom1 = list3.get(i);
                }
                //判断是否是大厅。如果是大厅则直接赋予状态

                if (yqgInformationRoom1.getRoomStatus().equals("1")) {
                    return AjaxResult.error("该位置已占用");
                } else {
                    yqgInformationRoom1.setRoomStatus("1");
                }

                //将项目，技师录入room表
                yqgInformationRoom1.setHandBrand(yqgConsumptionDetails.getHandBrand());
                yqgInformationRoom1.setEntryName(yqgConsumptionDetails.getEntryName());
                yqgInformationRoom1.setArtificer(String.valueOf(sysUser.getUserId()));
                yqgInformationRoom1.setActualTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));

                yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom1);
                //将技师状态修改为上钟
                YqgBaseinfo yqgBaseinfo = new YqgBaseinfo();
                YqgBaseinfo yB = new YqgBaseinfo();
                yqgBaseinfo.setUserName(sysUser.getUserName());
                List<YqgBaseinfo> list = yqgBaseinfoService.selectYqgBaseinfoList(yqgBaseinfo);
                for (int i = 0; i < list.size(); i++) {
                    yB = list.get(i);
                }
                yB.setPersonnelStatus("1");
                yqgBaseinfoService.updateYqgBaseinfo(yB);
                //新建项目表对象做查询
                YqgInformationProject yqgInformationProject = new YqgInformationProject();
                //查询项目信息
                yqgInformationProject.setEntryName(yqgConsumptionDetails.getEntryName());
                List<YqgInformationProject> a = yqgInformationProjectService.selectYqgInformationProjectList(yqgInformationProject);
                //以下为吧台需要 字段数据
                /**
                 * 添加用户信息
                 */
                //添加用户id
                yqgConsumptionDetails.setUserId(sysUser.getUserId());
                //添加用户姓名
                yqgConsumptionDetails.setUserName(sysUser.getUserName());
                //添加用户部门
                yqgConsumptionDetails.setDeptId(sysUser.getDeptId());
                //添加昵称
                yqgConsumptionDetails.setNickName(sysUser.getNickName());
                //添加手牌状态
                yqgConsumptionDetails.setHandState("1");
                yqgConsumptionDetails.setDepartment("4");
                /**
                 * 添加项目信息
                 */
                //添加项目名称
                yqgConsumptionDetails.setEntryName(a.get(0).getEntryName());
                //添加项目类别
                yqgConsumptionDetails.setProjectCategory(a.get(0).getProjectCategory());
                //添加项目代码
                yqgConsumptionDetails.setMnemonicCode(a.get(0).getMnemonicCode());
                //添加代码
                yqgConsumptionDetails.setProjectCode(a.get(0).getProjectCode());
                //添加单位
                yqgConsumptionDetails.setUnit(a.get(0).getUnit());
                //添加单价
                yqgConsumptionDetails.setUnitPrice(a.get(0).getUnitPrice());
                //添加提成
                yqgConsumptionDetails.setCommissionPrice(a.get(0).getCommissionPrice());
                yqgConsumptionDetails.setQuantity("1");
                yqgConsumptionDetails.setTotalAmount(a.get(0).getUnitPrice());
                /**
                 * 账单信息
                 */
                //添加账单id
                yqgConsumptionDetails.setBarBillsId(batailist.get(0).getID());
                //添加留牌状态
                yqgConsumptionDetails.setRetentionStatus(batailist.get(0).getRetentionStatus());
                //添加并牌状态
                yqgConsumptionDetails.setMergeStatus(batailist.get(0).getMergeStatus());
                //添加同来
                yqgConsumptionDetails.setTogether(batailist.get(0).getTogether());
                //添加到店时间
                yqgConsumptionDetails.setOpeningTime(DateUtils.getNowDate());
                //添加手牌类别
                yqgConsumptionDetails.setHandCategory(batailist.get(0).getHandCategory());
                //原手牌
                yqgConsumptionDetails.setOriginalHand(batailist.get(0).getOriginalHand());
                //交班状态
                yqgConsumptionDetails.setHandoverStatus(batailist.get(0).getHandoverStatus());
                /**
                 * 消费信息
                 */
                //添加录单时间
                yqgConsumptionDetails.setRecordingTime(yqgConsumptionDetails.getClockTime());
                //添加数量
                if (yqgConsumptionDetails.getQuantity() == null) {
                    yqgConsumptionDetails.setQuantity("1");
                }
                //添加消费状态
                yqgConsumptionDetails.setConsumptionStatus("0");
                //将上钟时间时分秒存入note2
                yqgConsumptionDetails.setNote2(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
                String qb = yqgConsumptionDetails.getNote1();
                yqgConsumptionDetails.setNote1("");
                yqgConsumptionDetailsService.insertYqgConsumptionDetails(yqgConsumptionDetails);
                //叫去上钟时将数据传入技师上钟情况表
                YqgTechnicianClockTable yqgTechnicianClockTable = new YqgTechnicianClockTable();
                yqgTechnicianClockTable.setRegistrationTime(DateUtils.getNowDate());
                yqgTechnicianClockTable.setUpclockPosition(yqgConsumptionDetails.getSeat());
                yqgTechnicianClockTable.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
                yqgTechnicianClockTable.setClockTime(yqgConsumptionDetails.getClockTime());
                yqgTechnicianClockTable.setEntryName(yqgConsumptionDetails.getEntryName());
                yqgTechnicianClockTable.setTableCreationTime(new Date());
                yqgTechnicianClockTable.setHandBrand(yqgConsumptionDetails.getHandBrand());
                yqgTechnicianClockTable.setNote1("1");
                if (qb.equals("1")) {
                    yqgTechnicianClockTable.setClickTrumpet("1");
                } else {
                    yqgTechnicianClockTable.setOrderLarge("1");
                }
                yqgTechnicianClockTableService.insertYqgTechnicianClockTable(yqgTechnicianClockTable);


                YqgTechnicianRehearsal yqgTechnicianRehearsal = new YqgTechnicianRehearsal();
                yqgTechnicianRehearsal.setNote1(sysUser.getUserName());
                List<YqgTechnicianRehearsal> listTR = yqgTechnicianRehearsalService.selectYqgTechnicianRehearsalList(yqgTechnicianRehearsal);
                for (int i = 0; i < listTR.size(); i++) {
                    listTR.get(i).setNote3("出勤");
                    yqgTechnicianRehearsalService.updateYqgTechnicianRehearsal(listTR.get(i));
                }


                return AjaxResult.success("上钟成功");
            }
        }
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/xiazhong")
    //下钟
    public AjaxResult xiazhong() {
        //新建消费表对象作为查询参数、接受查询结果
        YqgConsumptionDetails yqgConsumptionDetails1 = new YqgConsumptionDetails();
        YqgConsumptionDetails yqgConsumptionDetails = new YqgConsumptionDetails();
        //新建room表对象作为查询参数、接受查询结果
        YqgInformationRoom yqgInformationRoom = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom1 = new YqgInformationRoom();
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //将技师状态改为空闲
        YqgBaseinfo yqgBaseinfo = new YqgBaseinfo();
        YqgBaseinfo yB = new YqgBaseinfo();
        yqgBaseinfo.setUserName(sysUser.getUserName());
        List<YqgBaseinfo> listB = yqgBaseinfoService.selectYqgBaseinfoList(yqgBaseinfo);
        for (int j = 0; j < listB.size(); j++) {
            yB = listB.get(j);
        }
        yB.setPersonnelStatus("0");
        yqgBaseinfoService.updateYqgBaseinfo(yB);
        //查询目前上钟的记录
        yqgConsumptionDetails1.setUserId(sysUser.getUserId());
        yqgConsumptionDetails1.setNextClockStatus("1");
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(yqgConsumptionDetails1);
        if (list.size() == 0) {
            //上钟记录为0不行
            String message = "请先起钟";
            return AjaxResult.error(message);
        }
        for (int i = 0; i < list.size(); i++) {
            //将room表状态改成空闲并修改其中两个字段
            yqgInformationRoom.setRoomNumber(list.get(i).getSeat());
            List<YqgInformationRoom> list3 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom);
            for (int j = 0; j < list3.size(); j++) {
                yqgInformationRoom1 = list3.get(j);
            }
            //将其中技师，项目清除
            yqgInformationRoom1.setEntryName("");
            yqgInformationRoom1.setArtificer("");
            //状态改成空闲
            if (yqgInformationRoom1.getRoomType().equals("003")) {
                yqgInformationRoom1.setRoomStatus("0");
            } else {
                yqgInformationRoom1.setRoomStatus("2");
            }
            yqgInformationRoom1.setActualTime("");

            yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom1);
            //将查询结果拼两个新字段作为修改条件
            list.get(i).setNextClockTime(DateUtils.getNowDate());
            list.get(i).setNextClockStatus("0");
            //将下钟时间转化成String类型存入note3中
            list.get(i).setNote3(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
            //修改消费表，技师下钟
            yqgConsumptionDetailsService.updateYqgConsumptionDetails(list.get(i));
        }
        //下钟时修改上钟情况表
        YqgTechnicianClockTable yqgTechnicianClockTable = new YqgTechnicianClockTable();
        yqgTechnicianClockTable.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
        yqgTechnicianClockTable.setNote1("1");
        List<YqgTechnicianClockTable> ListTC = yqgTechnicianClockTableService.selectYqgTechnicianClockTableList(yqgTechnicianClockTable);
        for (int q = 0; q < ListTC.size(); q++) {
            ListTC.get(q).setNextClockTime(DateUtils.getNowDate());
            ListTC.get(q).setNote1("2");
            yqgTechnicianClockTableService.updateYqgTechnicianClockTable(ListTC.get(q));
        }


        YqgTechnicianRehearsal yqgTechnicianRehearsal = new YqgTechnicianRehearsal();
        yqgTechnicianRehearsal.setNote1(sysUser.getUserName());
        List<YqgTechnicianRehearsal> listTR = yqgTechnicianRehearsalService.selectYqgTechnicianRehearsalList(yqgTechnicianRehearsal);
        for (int i = 0; i < listTR.size(); i++) {
            listTR.get(i).setNote3("空闲");
            yqgTechnicianRehearsalService.updateYqgTechnicianRehearsal(listTR.get(i));
        }
        //如果没有就先上种
        return AjaxResult.success("下钟成功");
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PostMapping("/huanzhong/{leftid}/{rightid}")
    //换钟
    public AjaxResult huanzhong(@PathVariable("leftid") String leftid, @PathVariable("rightid") String rightid) {
        //前台 穿了两个参数，是拼在路径后面的 leftid是详细表的id，rightid是项目表id
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        YqgInformationRoom yqgInformationRoom = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom1 = new YqgInformationRoom();
        //查询对应id的数据
        YqgConsumptionDetails yqgConsumptionDetails = yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(Long.valueOf(leftid));
        YqgInformationProject yqgInformationProject = yqgInformationProjectService.selectYqgInformationProjectByID(Long.valueOf(rightid));
        YqgTechnicianClockTable yqgTechnicianClockTable = new YqgTechnicianClockTable();
        YqgTechnicianClockTable yqgTechnicianClockTable1 = new YqgTechnicianClockTable();
        yqgTechnicianClockTable.setEntryName(yqgConsumptionDetails.getEntryName());
        yqgTechnicianClockTable.setNote1("1");
        yqgTechnicianClockTable.setHandBrand(yqgConsumptionDetails.getHandBrand());
        yqgTechnicianClockTable.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
        List<YqgTechnicianClockTable> ListTC = yqgTechnicianClockTableService.selectYqgTechnicianClockTableList(yqgTechnicianClockTable);
        for (int i = 0; i < ListTC.size(); i++) {
            yqgTechnicianClockTable1 = ListTC.get(i);

        }
        yqgTechnicianClockTable1.setClockTime(DateUtils.getNowDate());
        yqgTechnicianClockTable1.setEntryName(yqgInformationProject.getEntryName());
        //如果消费表中那条数量只有一个，直接修改项目信息
        if (yqgConsumptionDetails.getQuantity().equals("1")) {
            yqgConsumptionDetails.setEntryName(yqgInformationProject.getEntryName());
            yqgConsumptionDetails.setProjectCode(yqgInformationProject.getProjectCode());
            yqgConsumptionDetails.setProjectCategory(yqgInformationProject.getProjectCategory());
            yqgConsumptionDetails.setMnemonicCode(yqgInformationProject.getMnemonicCode());
            yqgConsumptionDetails.setUnit(yqgInformationProject.getUnit());
            yqgConsumptionDetails.setUnitPrice(yqgInformationProject.getUnitPrice());
            yqgConsumptionDetails.setCommissionPrice(yqgInformationProject.getCommissionPrice());
            yqgConsumptionDetails.setTotalAmount(yqgInformationProject.getUnitPrice());
            yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails);
            yqgInformationRoom.setRoomNumber(yqgConsumptionDetails.getSeat());
            //取出对应房间的那一条数据
            List<YqgInformationRoom> list3 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom);
            for (int i = 0; i < list3.size(); i++) {
                yqgInformationRoom1 = list3.get(i);
            }
            //判断是否是大厅。如果是大厅则直接赋予状态
            //将项目，技师录入room表
            yqgInformationRoom1.setEntryName(yqgConsumptionDetails.getEntryName());
            yqgInformationRoom1.setArtificer(String.valueOf(sysUser.getUserId()));
            yqgInformationRoom1.setActualTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
            yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom1);
            return AjaxResult.success("换钟成功");
        } else {
            //如果如果消费表中那条数量不止一个，改一个，增一个
            //先增一个
            //新建消费表对象存储新增的
            YqgConsumptionDetails yCD = new YqgConsumptionDetails();
            //新增的项目内容
            yCD.setEntryName(yqgInformationProject.getEntryName());
            yCD.setProjectCode(yqgInformationProject.getProjectCode());
            yCD.setProjectCategory(yqgInformationProject.getProjectCategory());
            yCD.setMnemonicCode(yqgInformationProject.getMnemonicCode());
            yCD.setUnit(yqgInformationProject.getUnit());
            yCD.setUnitPrice(yqgInformationProject.getUnitPrice());
            yCD.setCommissionPrice(yqgInformationProject.getCommissionPrice());
            yCD.setTotalAmount(yqgInformationProject.getUnitPrice());
            yCD.setQuantity(String.valueOf(1));
            //原来其中包含内容
            yCD.setUserId(yqgConsumptionDetails.getUserId());
            yCD.setDeptId(yqgConsumptionDetails.getDeptId());
            yCD.setNickName(yqgConsumptionDetails.getNickName());
            yCD.setUserName(yqgConsumptionDetails.getUserName());
            yCD.setHandBrand(yqgConsumptionDetails.getHandBrand());
            yCD.setOriginalHand(yqgConsumptionDetails.getOriginalHand());
            yCD.setHandCategory(yqgConsumptionDetails.getHandCategory());
            yCD.setHandState(yqgConsumptionDetails.getHandState());
            yCD.setRetentionStatus(yqgConsumptionDetails.getRetentionStatus());
            yCD.setMergeStatus(yqgConsumptionDetails.getMergeStatus());
            yCD.setOpeningTime(yqgConsumptionDetails.getOpeningTime());
            yCD.setTogether(yqgConsumptionDetails.getTogether());
            yCD.setHandoverStatus(yqgConsumptionDetails.getHandoverStatus());
            yCD.setBarBillsId(yqgConsumptionDetails.getBarBillsId());
            yCD.setRecordingTime(yqgConsumptionDetails.getRecordingTime());
            yCD.setSeat(yqgConsumptionDetails.getSeat());
            yCD.setConsumptionStatus(yqgConsumptionDetails.getConsumptionStatus());
            yCD.setClockTime(yqgConsumptionDetails.getClockTime());
            yCD.setNextClockStatus(yqgConsumptionDetails.getNextClockStatus());
            yCD.setRecordEmployeeNumber(yqgConsumptionDetails.getRecordEmployeeNumber());
            yCD.setNote2(yqgConsumptionDetails.getNote2());
            //新增
            yqgConsumptionDetailsService.insertYqgConsumptionDetails(yCD);
            //修改一条
            //设置数量减一
            Long a = Long.valueOf(yqgConsumptionDetails.getQuantity()) - 1;
            //价格也减一份的
            Long b = Long.valueOf(yqgConsumptionDetails.getTotalAmount()) - Long.valueOf(yqgConsumptionDetails.getUnitPrice());
            yqgConsumptionDetails.setQuantity(String.valueOf(a));
            yqgConsumptionDetails.setTotalAmount(String.valueOf(b));
            //修改
            yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails);
            return AjaxResult.success("换钟成功");
        }
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/huanfang")
    //换房
    public AjaxResult huanfang(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        //新建消费表对象
        YqgConsumptionDetails y1 = new YqgConsumptionDetails();
        YqgConsumptionDetails y2 = new YqgConsumptionDetails();
        //新建房间表对象
        YqgInformationRoom yqgInformationRoom = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom1 = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom2 = new YqgInformationRoom();
        YqgInformationRoom yqgInformationRoom3 = new YqgInformationRoom();
        //获取登录用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        //查询一下新房间是否被占用
        yqgInformationRoom.setRoomNumber(yqgConsumptionDetails.getSeat());
        List<YqgInformationRoom> list2 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom);
        for (int i = 0; i < list2.size(); i++) {
            yqgInformationRoom1 = list2.get(i);
        }
        if (yqgInformationRoom1.getRoomStatus().equals("1")) {
            return AjaxResult.error("该位置已占用");
        }
        //设置查询条件查询现在上钟位置
        y1.setUserId(sysUser.getUserId());
        y1.setNextClockStatus("1");
        List<YqgConsumptionDetails> list = yqgConsumptionDetailsService.selectYqgConsumptionDetailsList(y1);
        for (int i = 0; i < list.size(); i++) {
            //用y2接查询结果
            y2 = list.get(i);
        }
        //现在y2是上钟记录的最后一条，
        yqgInformationRoom2.setRoomNumber(y2.getSeat());
        List<YqgInformationRoom> list1 = yqgInformationRoomService.selectYqgInformationRoomList(yqgInformationRoom2);
        for (int i = 0; i < list1.size(); i++) {
            yqgInformationRoom3 = list1.get(i);
        }
        //现在查出的是这个技师现在的上钟位置
        //用name接一下现在执行的项目
        String name = yqgInformationRoom3.getEntryName();
        //如果现在上钟的是大厅，把他状态改成空闲，其中项目技师清理掉

        yqgInformationRoom3.setRoomStatus("0");
        yqgInformationRoom3.setEntryName("");
        yqgInformationRoom3.setArtificer("");

        //将旧的房间更新
        yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom3);
        //更新一下消费表中的这次上钟的所有记录的位置信息
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setSeat(yqgConsumptionDetails.getSeat());
            yqgConsumptionDetailsService.updateYqgConsumptionDetails(list.get(i));
        }
        //将新的位置附上信息
        yqgInformationRoom1.setEntryName(name);
        yqgInformationRoom1.setArtificer(String.valueOf(sysUser.getUserId()));

        yqgInformationRoom1.setRoomStatus("1");

        //将新的房间更新
        yqgInformationRoomService.updateYqgInformationRoom(yqgInformationRoom1);
        return AjaxResult.success("换房成功");
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/udA")
    public AjaxResult PA(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        YqgConsumptionDetails yqgConsumptionDetails1 = yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(yqgConsumptionDetails.getID());
        yqgConsumptionDetails1.setTechnicianEvaluation("一星");
        yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails1);
        String message = "评级成功";
        return AjaxResult.success(message);
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/udB")
    public AjaxResult PB(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        YqgConsumptionDetails yqgConsumptionDetails1 = yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(yqgConsumptionDetails.getID());
        yqgConsumptionDetails1.setTechnicianEvaluation("两星");
        yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails1);
        String message = "评级成功";
        return AjaxResult.success(message);
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/udC")
    public AjaxResult PC(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        YqgConsumptionDetails yqgConsumptionDetails1 = yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(yqgConsumptionDetails.getID());
        yqgConsumptionDetails1.setTechnicianEvaluation("三星");
        yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails1);
        String message = "评级成功";
        return AjaxResult.success(message);
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/udD")
    public AjaxResult PD(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        YqgConsumptionDetails yqgConsumptionDetails1 = yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(yqgConsumptionDetails.getID());
        yqgConsumptionDetails1.setTechnicianEvaluation("四星");
        yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails1);
        String message = "评级成功";
        return AjaxResult.success(message);
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/udE")
    public AjaxResult PE(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        YqgConsumptionDetails yqgConsumptionDetails1 = yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(yqgConsumptionDetails.getID());
        yqgConsumptionDetails1.setTechnicianEvaluation("五星");
        yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails1);
        String message = "评级成功";
        return AjaxResult.success(message);
    }

    @GetMapping(value = "/{ID}")
    public AjaxResult idcx(@PathVariable("ID") Long ID) {

        return success(yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(ID));
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        return toAjax(yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails));
    }

    @GetMapping("/paidui")
    public AjaxResult paidui() {
        //获取当前用户
        LoginUser loginUser = getLoginUser();
        SysUser sysUser = loginUser.getSysUser();
        YqgTechnicianRehearsal yqgTechnicianRehearsal1 = new YqgTechnicianRehearsal();
        yqgTechnicianRehearsal1.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
        List<YqgTechnicianRehearsal> List1 = yqgTechnicianRehearsalService.selectYqgTechnicianRehearsalList(yqgTechnicianRehearsal1);
        if (List1.size() != 0) {
            return AjaxResult.error("已经排队了");
        }
        YqgTechnicianRehearsal yqgTechnicianRehearsal = new YqgTechnicianRehearsal();
        List<YqgTechnicianRehearsal> list = yqgTechnicianRehearsalService.selectYqgTechnicianRehearsalList(yqgTechnicianRehearsal);
        int m = 1;
        Long jl;
        for (int i = 0; i < list.size(); i++) {
            if (Integer.parseInt(list.get(i).getRowNumber()) > m) {
                m = Integer.parseInt(list.get(i).getRowNumber());
                jl = list.get(i).getId();
            }
        }
        yqgTechnicianRehearsal.setRowNumber(String.valueOf(m + 1));
        yqgTechnicianRehearsal.setTechnicianNumber(String.valueOf(sysUser.getUserId()));
        yqgTechnicianRehearsal.setNote1(sysUser.getUserName());
        yqgTechnicianRehearsal.setNote2(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm", DateUtils.getNowDate()));
        yqgTechnicianRehearsal.setNote4(sysUser.getNickName());
        YqgBaseinfo yqgBaseinfo = new YqgBaseinfo();
        yqgBaseinfo.setUserName(sysUser.getUserName());
        List<YqgBaseinfo> listb = yqgBaseinfoService.selectYqgBaseinfoList(yqgBaseinfo);
        String zt = "";
        for (int i = 0; i < listb.size(); i++) {
            zt = listb.get(i).getPersonnelStatus();
        }
        if (zt.equals("1")) {
            zt = "在岗";
        }
        if (zt.equals("0")) {
            zt = "空闲";
        }
        yqgTechnicianRehearsal.setNote3(zt);
        yqgTechnicianRehearsalService.insertYqgTechnicianRehearsal(yqgTechnicianRehearsal);
        return AjaxResult.success("排队成功");
    }

    @GetMapping("/listTR")
    public TableDataInfo list(YqgTechnicianRehearsal yqgTechnicianRehearsal) {
        startPage();
        List<YqgTechnicianRehearsal> list = yqgTechnicianRehearsalService.selectYqgTechnicianRehearsalList(yqgTechnicianRehearsal);
        return getDataTable(list);
    }

    @GetMapping(value = "/GD/{IDk}")
    public AjaxResult getInfo(@PathVariable("IDk") Long ID) {
        return success(yqgConsumptionDetailsService.selectYqgConsumptionDetailsByID(ID));
    }

    @Log(title = "消费详细", businessType = BusinessType.UPDATE)
    @PutMapping("/u1")
    public AjaxResult update(@RequestBody YqgConsumptionDetails yqgConsumptionDetails) {
        return toAjax(yqgConsumptionDetailsService.updateYqgConsumptionDetails(yqgConsumptionDetails));
    }
}
